import time

from selenium import webdriver  # 导入包
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.keys import Keys


class Login:
    """用于打开百度首页并登录，输入搜索信息，断言页面信息
        args:

        return:
    """
    # 设置webdriver地址
    # System.setProperty()
    # 启动浏览器，创建会话
    # path = r'C:\app-dev\chromedriver-win64\chromedriver-win64\chromedriver.exe'
    driver = webdriver.Edge()
    # 指定访问地址
    driver.get("https://www.baidu.com")
    # 断言判断是否打开baidu
    assert '百度一下，你就知道' in driver.title

    # 点击登录按钮
    elem = driver.find_element(By.ID, 's-top-loginbtn')
    # 点击定位区域
    elem.click()
    # 等待登录窗口加载
    sleep(3)
    click_mobile_input = driver.find_element(By.ID, 'TANGRAM__PSP_11__userNameWrapper')
    click_mobile_input.click()

    # click_login_input_mobile = driver.find_element(By.ID,'TANGRAM__PSP_11__userName')
    # click_login_input_mobile.click()
    mobile_input = driver.find_element(By.NAME, 'userName')
    mobile_input.clear()
    password_input = driver.find_element(By.ID, 'TANGRAM__PSP_11__password')
    password_input.clear()

    sleep(3)
    mobile = "_____圣婪"
    password = 'beiaidgab123'
    mobile_input.send_keys(mobile)
    password_input.send_keys(password)
    sleep(3)
    #点击同意协议
    click_isAgree = driver.find_element(By.NAME,'isAgree')
    click_isAgree.click()
    sleep(3)

    #点击登录
    click_loginBtn = driver.find_element(By.ID,'TANGRAM__PSP_11__submit')
    click_loginBtn.click()
    sleep(10)


    # click_mobile_input = driver.find_element(By.ID,'TANGRAM__PSP_11__userName').click()
    #
    # mobile_input = driver.find_element(By.NAME,'TANGRAM__PSP_11__userName')
    # sleep(10)
    # mobile_input.send_keys('_____圣婪' + Keys.RETURN)
    # sleep(4)
    # # elem = driver.find_element(By.NAME,'wd')
    # elem.send_keys('seleniumhq' + Keys.RETURN)

    # 设置显性等待时间
    # sleep(10)
    # #
    # # f=driver.find_element(By.XPATH, '//*[@id="u1"]//a[@id="s-top-loginbtn"]')
    # f = driver.find_element(By.CLASS_NAME, "bg s_ipt_wr new-pmd quickdelete-wrap",['123'])
    # f.click()
    # f.send_keys("1234")
    # print(type(f))

    # //*[@id="u1"]//a[@id="s-top-loginbtn"]

    # 关闭浏览器
    driver.quit()
